﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BCMS.Business.DataContract;
using BCMS.Business.Implementation;
using BCMS.FrontEnd.DataContract;
namespace BCMS.Forms
{
    public partial class frmUserUpdate : Form
    {
        public frmUserUpdate(int uID)
        {
            this.Font = SystemFonts.MessageBoxFont;
            if (uID <= 0) throw new Exception("Người dùng không tồn tại.");
            userId = uID;
            InitializeComponent();
            DALclient client = new DALclient();
            UserUI uInfo = client.getUserById(uID);
            if (uInfo != null)
            {
                txtUserName.Text = uInfo.UserName;
                txtFullName.Text = uInfo.FullName;
                txtEmail.Text = uInfo.Email;
                txtPhone.Text = uInfo.Phone;
                txtAddress.Text = uInfo.Address;
                txtPosition.Text = uInfo.Position;
                txtDepartment.Text = uInfo.Department;
            }
            else throw new Exception("Người dùng không tồn tại.");
        }
        private int userId = -1;
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                // check for existed
                DALclient client = new DALclient();
                client.updateUser(userId,
                                        txtFullName.Text.Trim(),
                                        txtEmail.Text.Trim(),
                                        txtPhone.Text.Trim(),
                                        txtAddress.Text.Trim(),
                                        txtPosition.Text.Trim(),
                                        txtDepartment.Text.Trim());
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        private void btnChangePassword_Click(object sender, EventArgs e)
        {
            frmUserResetPassword frm = new frmUserResetPassword(userId);
            frm.ShowDialog();
        }

        private void frmUserUpdate_Load(object sender, EventArgs e)
        {

        }
    }
}
